<?php
use yii\helpers\Url;

$web = Url::base();
$integral_unit = \app\models\Mall::getCurrentInstitutionIntegralUnit();
$site_name = \app\models\Mall::getCurrentInstitutionSiteName();
$institution_code = \app\models\Mall::getCurrentInstitutionCode();
$this->title = $site_name.'->'.$integral_unit.'转赠';
?>
<link rel="stylesheet" type="text/css" href="<?= $web ?>/css/mall/user-present.css"/>
<script type="application/javascript">

    function onConfirm() {
        var user_integral = $("#user_integral").val();
        var number = $("#number").val();
        var integral = $("#integral").val();
        var data = {};
        data.number = number;
        data.integral = integral;

        if (number == null || number == '') {
            alert("请输入对方手机号");
            return;
        }
        if (!checkMobile(number)) {
            alert("输入的手机号有误，请重新输入");
            return;
        }
        if (integral == null || integral == '') {
            alert("请输入转赠<?= $integral_unit ?>");
            return;
        }
        if (parseInt(integral) > parseInt(user_integral)) {
            alert("转赠<?= $integral_unit ?>不能大于账户余额");
            return;
        }

        if (confirm("确定转赠吗？")) {
            requestJson("integral-transfer-handler", data, true, function (response) {
                if (response.status == 0) {
                    alert('操作成功！');
                    var href = decodeURIComponent(window.location.href);
                    window.location.href = href;
                } else {
                    alert('操作失败！' + response.message);
                }
            });
        }
    }

</script>

<div class="my-information">
    <div class="menu fl">
        <ul>
            <li><a href="user-information?institution_code=<?= $institution_code ?>">个人信息</a></li>
            <li><a href="user-card?institution_code=<?= $institution_code ?>">我的卡卷</a></li>
            <li><a href="javascript:void(0)" class="cur"><?= $integral_unit ?>转赠</a></li>
            <li><a href="order-list?institution_code=<?= $institution_code ?>">我的订单</a></li>
            <li><a href="user-account-record?institution_code=<?= $institution_code ?>">我的<?= $integral_unit ?></a></li>
            <li><a href="user-address?institution_code=<?= $institution_code ?>">收货地址</a></li>
        </ul>
    </div>
    <div class="data fl">
        <div class="title">
            <p><?= $integral_unit ?>转赠</p>
        </div>
        <div class="present">
            <p class="integral-balance"><?= $integral_unit ?>账户余额：<?php if($user_info!=null && $user_info!='') echo number_format($user_info['integral']); ?></p>
            <div class="user">
                <div class="user-phone">
                    <span>对方手机号</span>
                    <input id="number" type="tel" class="number" type="text" value=""/>
                </div>
                <div class="user-num">
                    <span>转赠<?= $integral_unit ?></span>
                    <input id="user_integral" type="hidden" class="number"value="<?php if($user_info!=null && $user_info!='') echo $user_info['integral']; else echo 0 ?>"/>
                    <input id="integral" type="number" min="0" max="<?php if($user_info!=null && $user_info!='') echo number_format($user_info['integral']); else echo 0 ?>" value="" onkeyup="checkNumVal_int(this)"/>
                </div>
            </div>
            <a href="javascript:void(0)" class="sure-btn" onclick="onConfirm()" >确定</a>
        </div>
    </div>
</div>